package mapmap;

import java.util.HashMap;

/**
 * 集合嵌套:以Map套Map为例
 */
public class MapMapDemo01 {
    public static void main(String[] args) {
        //1.构建容器的数据,构建数据从内向外
        HashMap<String, String> student01 = new HashMap<>();
        student01.put("1001", "张三");
        student01.put("1002", "李四");
        student01.put("1003", "王五");

        HashMap<String, String> student02 = new HashMap<>();
        student02.put("2001", "小白");
        student02.put("2003", "小明");
        student02.put("2005", "小红");

        //2.构建最外的HashMap<String,HashMap<String, String>>
        HashMap<String, HashMap<String, String>> classRoom = new HashMap<>();
        classRoom.put("一班", student01);
        classRoom.put("二班", student02);

        //3.遍历嵌套的集合(从外向内)
        //a.遍历的是每个班级
        for (String roomName : classRoom.keySet()) {
            //b.根据当前班级得到对应的学生容器
            HashMap<String, String> snosName = classRoom.get(roomName);
            //c.遍历当前学生容器
            for (String key : snosName.keySet()) {
                System.out.println(roomName + " " + key + " " + snosName.get(key));
            }
        }

    }
}
